var basic_hook = document.getElementById("hook_options");
basic_hook.addEventListener('onmouseover', () => {

});
var private_hook = document.getElementById("private_hook");
private_hook.addEventListener('click', () => {
    window.open(chrome.extension.getURL("options.html"))
});
var xpath = document.getElementById('get_xpath');
xpath.addEventListener('click', () => {
    chrome.tabs.query({
        active: true,
        currentWindow: true
    }, (tabs) => {
        let message = { action: 'get_xpath' }
        chrome.tabs.sendMessage(tabs[0].id, message, res => {
            alert('bg=>content')
            alert(res.state)
        })
    })
});
// bg---->popup------>content
// popup启动后需要重新刷新页面
// 更好的解决方案 =====> popup和options完成对hook功能的基本配置,并交由popup处理刷新
var reflesh = document.getElementById('reflesh');
reflesh.addEventListener('click', () => {
    chrome.tabs.query({
        active: true,
        currentWindow: true
    }, (tabs) => {
        chrome.storage.sync.get(['code'], (e) => {
            if (Object.values(e.code).every((e) => { e === undefined })) return;
            e.code.forEach(element => {
                let message = { action: 'other_hook', code: element.code }
                chrome.tabs.sendMessage(tabs[0].id, message, res => {
                    alert('bg=>content')
                    alert(res.state)
                })
            });
        })
    })
})